package com.maiji.cloud.microservice;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.maiji.cloud.entities.login.AreaInfo;
import com.maiji.cloud.entities.login.UserInfo;
import com.maiji.cloud.service.AreaInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/areaInfo/")
public class AreaInfoController {

    @Autowired
    private AreaInfoService areaInfoService;

    /**
     *  保存地理信息
     * @param areaInfo
     * @return
     */
    @PostMapping("saveAreaInfo")
    public Boolean saveAreaInfo (@RequestBody AreaInfo areaInfo) {
       if (areaInfo == null) return false;
       if (areaInfoService.insert(areaInfo)) return true;
       return false;
    }

    /**
     *  获取地理信息
     * @param areaInfoId
     * @return
     */
    @GetMapping("getAreaInfoById/{areaInfoId}")
    public AreaInfo getAreaInfoById (@PathVariable String areaInfoId) {
       if (areaInfoId == null) return null;
        return areaInfoService.selectById(areaInfoId);
    }

    /**
     *  修改地理信息
     * @param areaInfo
     * @return
     */
    @PostMapping("updateAreaInfo")
    public Boolean updateAreaInfo (@RequestBody AreaInfo areaInfo) {
        if (areaInfo == null) return false;
        if (areaInfoService.updateById(areaInfo)) return true;
        return false;
    }

    @PostMapping("selectList")
    public List<AreaInfo> selectList (@RequestBody Map<String, Object> map) {
        EntityWrapper<AreaInfo> entityWrapper = new EntityWrapper<>();
        entityWrapper.in("uu_id", (List<String>) map.get("areaInfoIds"));
        return areaInfoService.selectList(entityWrapper);
    }
    
    

}
